window.onload = initialize;
var map;
var latlng = new google.maps.LatLng(30.2244392, 120.0299263);
function initialize() {
	var mapOptions = {
		zoom : 14, 
		center : latlng, 
		mapTypeId : google.maps.MapTypeId.HYBRID,
		scaleControl : true, 
		mapTypeControl : true,
		backgroundColor : '#000000',
		navigationControl:true,
		mapTypeControlOptions : {
		style : google.maps.MapTypeControlStyle.DROPDOWN_MENU
		}
	};
	map = new google.maps.Map(document.getElementById("map_canvas"),mapOptions);
		
}
function findaddress()
{
	var ad = document.getElementById("splace").value;
	
	var geocoder = new google.maps.Geocoder();

	
	
	geocoder.geocode({'address':ad},function(results,status)
	{
		
		if(status == google.maps.GeocoderStatus.OK)
		{
			
			//如果找到了。
			map.setCenter(results[0].geometry.location);
			var marker = new google.maps.Marker(
			{
				position:results[0].geometry.location,
				title:"hello"+results[0].address_components[0].long_name.toString(),
				map:map
			});
			var message ="<div><font color=red>这里是："+results[0].address_components[0].long_name.toString()+"</font><br>"+
					"<font>经度：</font>"+results[0].geometry.location.lng()+"<br>" +
					"<font>纬度: </font>"+results[0].geometry.location.lat()+"<br></div>";
			var info = new google.maps.InfoWindow(
			{
				content:message
			});
			google.maps.event.addListener(marker,"click",function()
			{
				info.open(map,marker);
		
			});
			
		}
		else
		{
			alert("木有");
		}
	}
	
	);
}
function findaddressbylatlng()
{
	var latlngstr = document.getElementById('latlng').value;//从文本框获得字串
	var lat = parseFloat(latlngstr.split(',',2)[0]);//纬度
	var lng = parseFloat(latlngstr.split(',',2)[1]);//经度
	latlng = new google.maps.LatLng(lat,lng);//位置
	
	var geocoder = new google.maps.Geocoder();//初始化了地址解析
	geocoder.geocode({'latLng':latlng},function(results,status)
	{
		
		if(status==google.maps.GeocoderStatus.OK)//如果找到了
		{
			map.setCenter(latlng);//设置地图中心
			/*
			 * 加入标记和弹出对话框
			 */
			var marker = new google.maps.Marker(
			{
				position:latlng,
				map:map
			});
			var message ="<div><font color=red>"+results[0].address_components[0].long_name.toString()+"</font><br>"+
					"<font>经度：</font>"+lng.toString()+"<br>" +
					"<font>纬度: </font>"+lat.toString()+"<br></div>";
			var info = new google.maps.InfoWindow(
			{content:message});
			google.maps.event.addListener(marker,"click",function()
			{
				info.open(map,marker);
			});
		}
	});
	
	
}








/*	function markplace(location)
	{
		
		var marker = new google.maps.Marker(
		{
			position:location,
			map:map,
			title:'nimei'
		});
		map.panTo(location);
		
	}*/
